<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>出库</title>
		<link rel="stylesheet" type="text/css" href="<c:url value='/css/maple.css'/>"></link>
		<style type="text/css">
			.tx td {
				padding: 3px;
			}
		</style>
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/jquery-ui-1.9.2.custom.css" />
		<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-ui-1.9.2.custom.js"></script>
		<script type="text/javascript">
			//回显仓库下拉菜单
			$(document).ready(function() {
				var url = "<%=request.getContextPath()%>/goodsAction_findAllStore";
				$.post(
					//路径
					url,
					//回调函数
					function(data) {
						for ( var i in data) {
							$("#selectStores").append("<option  value='"+data[i].id+"'>"+data[i].name+"</option>");
						}
					},
					//返回类型
					"json"
				);
			});
			//验证商品简拼是否存在|并且获取数据对象
			function checkNm() {
				//获取简记码的值
				var nm = $("[name='nm']").val();
				var url = "<%=request.getContextPath()%>/checkByStoreNm2";
				$.post(
					//路径
					url,
					//传值
					{nm:nm},
					//回调函数
					function(data) {
						if(data.length>0) {
							for ( var i in data) {
								$("[name='nm']").val(data[i].nm);
								$("[name='goodname']").val(data[i].goodname);
								$("[name='unit']").val(data[i].unit);
								//商品id
								var id = data[i].id;
								$("[name='id']").val(id);
								
								//商品外键storeid
								var storeid = data[i].storeid;
								//仓库id
								var id = data[i].id;
								if (id==storeid) {
									$("[name='storeid']").append("<option selected='selected' value='"+data[i].id+"'>"+data[i].name+"</option>");
								}
							}
						}
					},
					//返回类型
					"json"
				);
			};
			function goodOut(){
				var url = "${pageContext.request.contextPath}/goodsAction_out";
				$.post(
					//路径
					url,
					//传值
					{
						id:$("#id").val(),
						nm:$("#nm").val(),
						num:$("#num").val()
					},
					//回调函数
					function(data) {
						alert("123");
						if(data==true) {
							alert("出库成功");
							window.location.href="${pageContext.request.contextPath}/goodsAction_searchUI";
						}else if(data==false){
							alert("数量不足，请重试");
							window.location.href="${pageContext.request.contextPath}/goodsAction_outUI";
						}
					},
					//返回类型
					"json"
					);
				}
		</script>
	</head>
	<body>
	
		<table border="0" class="tx" width="100%">
			<tr>
				<td>
					当前位置&gt;&gt;首页&gt;&gt;出库
				</td>
			</tr>
		</table>
		<br>
		${requestScope.msg}
		<table border="0" width="100%" cellpadding="0" cellspacing="0">
			<tr valign="top">
				<td rowspan="2">
					<form action="" namespace="/" method="post" theme="simple" name="select">
						<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tx" align="center">
							<colgroup>
								<col width="20%" align="right">
								<col width="*%" align="left">
							</colgroup>
							<tr>
								<td bgcolor="a0c0c0" style="padding-left: 10px;" colspan="2" align="left">
									<b>货物出库登记：</b>
								</td>
							</tr>
							<tr>
								<td>
									简记码：
								</td>
								<td>
									<!--商品id-->
									<input type="hidden" name="id" id="id">
									<input type="text" style="border-color: green;" name="nm" onblur="checkNm()">
								</td>
							</tr>
							<tr>
								<td>
									货物名称：
								</td>
								<td>
									<input type="text" style="border-color: green;" name="goodname" id="goods_name">
								</td>
							</tr>
							<tr>
								<td>
									计量单位：
								</td>
								<td>
									<input type="text" style="border-color: green;" name="unit" id="unit">
								</td>
							</tr>
							<tr>
								<td>
									出库数量：
								</td>
								<td>
									<input type="text" style="border-color: green;" name="num" id="num">
								</td>
							</tr>
							<tr>
								<td>
									选择仓库：
								</td>
								<td>
									<select class="tx" style="width: 120px;" name="storeid" id="selectStores">
										<option value="">
											请选择仓库
										</option>
									</select>
								</td>
							</tr>
							<tr>
								<td colspan="2" align="center" style="padding-top: 10px;">
									<input class="tx" style="width: 120px; margin-right: 30px;" type="button" onclick="goodOut()" value="出库">
									<input class="tx" style="width: 120px; margin-right: 30px;" type="reset" value="取消">
								</td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
		</table>
	</body>
</html>

